package com.wgj.android.ui.activity;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jiaai.xui.adapter.XRecyclerViewAdapter;
import com.jiaai.xui.adapter.XViewHolder;
import com.jiaai.xui.adapter.decoration.DividerDecoration;
import com.jiaai.xui.utils.XDateUtils;
import com.jiaai.xui.utils.XDensityUtils;
import com.jiaai.xui.utils.http.HttpCallBack;
import com.jiaai.xui.utils.http.XHttp;
import com.jiaai.xui.view.widget.XToast;
import com.wgj.android.R;
import com.wgj.android.entity.HBDetial;
import com.wgj.android.entity.QDHS;
import com.wgj.android.http.WGJAPI;
import com.wgj.android.utils.CacheUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class HBDetialActivity extends AppCompatActivity {
    @BindView(R.id.list_view)
    RecyclerView listView;
    @BindView(R.id.notDataView)
    LinearLayout notDataView;
    @BindView(R.id.tv_totle)
    TextView tvTotle;
    private List<QDHS> qdhsArrayList = new ArrayList<>();
    private XRecyclerViewAdapter<QDHS> deliverAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hbdetial1);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {

        deliverAdapter = new XRecyclerViewAdapter<QDHS>(listView, qdhsArrayList, R.layout.qd_hs_item) {
            @Override
            protected void bindData(XViewHolder viewHolder, QDHS qdhs, int i) {

                viewHolder.setImageUrl(R.id.avater, qdhs.getAvater());
                viewHolder.setText(R.id.nickName, qdhs.getM_nick());
                viewHolder.setText(R.id.money, qdhs.getTake_money()+"元");
                viewHolder.setText(R.id.tv_time,qdhs.getTime());
            }
        };
        listView.setLayoutManager(new LinearLayoutManager(this));
        listView.setHasFixedSize(true);
        listView.addItemDecoration(new DividerDecoration(ContextCompat.getColor(this, R.color.transparent), XDensityUtils.dp2px(5f)));
        listView.setAdapter(deliverAdapter);
        getData(XDateUtils.format(new Date(), "yyyy-MM-dd"));

    }

    public void getData(String times) {
        XHttp.obtain().get(WGJAPI.getHbDetial(), null, new HttpCallBack<HBDetial>() {

            @Override
            public void onSuccess(HBDetial hbDetial) {
                // qdhsArrayList=hbDetial.getMySignRecord();
                if(hbDetial.getMySignRecord().size()==0){
                    notDataView.setVisibility(View.VISIBLE);
                    listView.setVisibility(View.GONE);
                }else {
                    qdhsArrayList.clear();
                    qdhsArrayList.addAll(hbDetial.getMySignRecord());
                    deliverAdapter.notifyDataSetChanged();
                    tvTotle.setText("总金额"+hbDetial.getCountMoney());
                }

            }

            @Override
            public void onFailed(int i, String s, boolean b) {
                XToast.error("异常");
            }
        });
    }
    @OnClick(R.id.tv_back)
    public void onBack(View v){
        finish();
    }
}
